
app.service('goodsListService',['$q','utilService','$http','$filter',function($q,utilService,$http,$filter){
    var _this_=this;

    _this_.updateStatus= function ($scope,id,status,shopId) {
        if(status==2){
            return;
        }

        //status=(status==3)?2:(status==0||status==4)?1:0;
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'goods/status',
            data:{id:id,status:status,shopId:shopId},
            method:"PUT"
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }

    //导出数据
    _this_.exportData = function($scope){
        $http({
            method:'POST',
            url:$scope.app.domain + 'report/shop/goods/list',
            data:$scope.param,
            responseType: "arraybuffer",
            headers:{'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
            transformRequest: function(obj) {
                var str = [];
                for(var p in obj){
                    str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                }
                return str.join("&");
            }
        }).success(function(data){
            var blob = new Blob([data], {type: "application/vnd.ms-excel"});
            var fileName ="店铺产品列表"+ (new Date()).getTime()+'.xls';
            var a = document.createElement("a");
            document.body.appendChild(a);
            a.download = fileName;
            a.href = URL.createObjectURL(blob);
            a.click();
        })
    }

    //查询预约信息
    this.checkReserve = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'goods/serve/id',
            params:{serveId:$scope.id}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        });
        return deferred.promise;
    }
}]);